package com.sky.utils;

import com.sky.constant.JwtClaimsConstant;
import com.sky.properties.JwtProperties;
import io.jsonwebtoken.Claims;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class GetOperatorId {
    @Autowired
    JwtProperties jwtProperties;
    @Resource
    HttpServletRequest request;

    public String getId() {
        //获取token，获取当前操作对象
        String token = request.getHeader(jwtProperties.getAdminTokenName());
        Claims jwt = JwtUtil.parseJWT(jwtProperties.getAdminSecretKey(), token);
        String id = jwt.get(JwtClaimsConstant.EMP_ID).toString();
        return id;
    }
}
